# coding=utf-8
import arcpy
path = r'D:\Test';
arcpy.env.workspace = path
shp = r'D:\Test\sc1.shp'.decode('utf-8')
cs = arcpy.da.UpdateCursor(shp,['SHAPE@','name','level','flowRiv','flowId','lpDisRiv'])

shp2 = r'D:\Test\sc2.shp'.decode('utf-8')
cs2 = arcpy.da.SearchCursor(shp2,['SHAPE@','name','level','rivId'])
i = 0
for row in cs:
    riverLastPoint = row[0].lastPoint
    riverLevel = row[2]
    disList = []
    for row2 in cs2:
        if row2[2] < riverLevel:
            distans = row2[0].distanceTo(riverLastPoint)
            nearestRivName = row2[1]
            res = [distans, nearestRivName,row2[3]]
            disList.append(res)
    cs2.reset()
    if(len(disList)>0):
        disList.sort(key=lambda x: x[0])
        print i,row[1],disList[0][1]
        i+=1
        row[3] = disList[0][1]
        row[4] = disList[0][2]
        row[5] = disList[0][0]
        cs.updateRow(row)

